package io.geekidea.boot.test.controller;

import io.geekidea.boot.auth.annotation.Permission;
import io.geekidea.boot.common.enums.SysLogType;
import io.geekidea.boot.framework.annotation.Log;
import io.geekidea.boot.framework.page.Paging;
import io.geekidea.boot.framework.response.ApiResult;
import io.geekidea.boot.test.dto.IssueFeedbackDto;
import io.geekidea.boot.test.query.IssueFeedbackQuery;
import io.geekidea.boot.test.service.IssueFeedbackService;
import io.geekidea.boot.test.vo.IssueFeedbackVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 问题反馈 控制器
 *
 * @author geekidea
 * @since 2025-03-26
 */
@Slf4j
@RestController
@Tag(name = "问题反馈")
@RequestMapping("/admin/issueFeedback")
public class IssueFeedbackController {

    @Autowired
    private IssueFeedbackService issueFeedbackService;

    /**
     * 添加问题反馈
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.ADD)
    @Operation(summary = "添加问题反馈")
    @PostMapping("/addIssueFeedback")
    @Permission("issue:feedback:add")
    public ApiResult addIssueFeedback(@Valid @RequestBody IssueFeedbackDto dto) {
        log.info("添加问题反馈：{}", dto);
        boolean flag = issueFeedbackService.addIssueFeedback(dto);
        return ApiResult.result(flag);
    }

    /**
     * 修改问题反馈
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.UPDATE)
    @Operation(summary = "修改问题反馈")
    @PostMapping("/updateIssueFeedback")
    @Permission("issue:feedback:update")
    public ApiResult updateIssueFeedback(@Valid @RequestBody IssueFeedbackDto dto) {
        log.info("修改问题反馈：{}", dto);
        boolean flag = issueFeedbackService.updateIssueFeedback(dto);
        return ApiResult.result(flag);
    }

    /**
     * 删除问题反馈
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.DELETE)
    @Operation(summary = "删除问题反馈")
    @PostMapping("/deleteIssueFeedback/{id}")
    @Permission("issue:feedback:delete")
    public ApiResult deleteIssueFeedback(@PathVariable Long id) {
        log.info("删除问题反馈：{}", id);
        boolean flag = issueFeedbackService.deleteIssueFeedback(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取问题反馈详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取问题反馈详情")
    @PostMapping("/getIssueFeedback/{id}")
    @Permission("issue:feedback:info")
    public ApiResult<IssueFeedbackVo> getIssueFeedback(@PathVariable Long id) {
        log.info("获取问题反馈详情：{}", id);
        IssueFeedbackVo issueFeedbackVo = issueFeedbackService.getIssueFeedbackById(id);
        return ApiResult.success(issueFeedbackVo);
    }

    /**
     * 获取问题反馈分页列表
     *
     * @param query
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取问题反馈分页列表")
    @PostMapping("/getIssueFeedbackPage")
    @Permission("issue:feedback:page")
    public ApiResult<IssueFeedbackVo> getIssueFeedbackPage(@Valid @RequestBody IssueFeedbackQuery query) {
        log.info("获取问题反馈分页列表：{}", query);
        Paging<IssueFeedbackVo> paging = issueFeedbackService.getIssueFeedbackPage(query);
        return ApiResult.success(paging);
    }

}
